package com.my.example;

import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 注解@Transactional失效的几种情况
 *
 * @author: marshal
 * @date: 2023-05-24 20:37
 */
public class TransactionalFailure {
    public void test1() {
        test2();
    }

    @Transactional
    public void test2() {

    }

    @Transactional(rollbackFor =  Exception.class, isolation = Isolation.DEFAULT)
    public void test3() {
        try {
            // doSomething
            update1();
            update2();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public Integer update1(){
        System.out.println("this is update1");
        return 1;
    }

    public Integer update2() {
        System.out.println("this is update2");
        return 2;
    }
}
